import store from '../store'
import router from '../router'

export function isLogin () {
    if (store.state.token && new Date().getTime() < parseInt(store.state.expire) && localStorage.getItem('__token')) {
      return true
    } else {
      return false
    }
}

export function checkLogin () {
  return new Promise((resolve, reject) => {
    if (isLogin()) {
      resolve('ok')
    } else {
      router.push({
        path: '/login',
        query: {
          front: 1 // 从前台自己判断登录状态，不经过路由判断
        }
      })
      reject(new Error('noLogin'))
    }
  })
}
